<template>
  <div>
      <!-- 子传父 -->
    
    <!-- 父传子 -->
    
    <!-- <div>{{inputName}}</div> -->
    <div v-for="(item,index) in draft" :key="index">
      <el-button @click="childClick(item)">点击触发</el-button>
      {{item.draftTitle}}
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      data: "",
       childValue: '1',
       draft:"",
    };
  },
  props:{inputName:String},
  mounted() {
    axios({
        url: "http://localhost:3000/getdraft",
        method: "get"
      }).then(response => {
        console.log(response);
        this.draft = response.data.message
      });
  },
  methods: {
      childClick (item) {
        sessionStorage.draftTitle = item.draftTitle
        
        // childByValue是在父组件on监听的方法
        // 第二个参数this.childValue是需要传的值
        const childValue = item.draftTitle
        this.$emit('childByValue', {childValue:childValue,name:this.childValue})
      },
    getInfo() {
      axios({
        url: "http://localhost:3000/gettest",
        method: "get"
      }).then(response => {
          this.data = response
        console.log(response);
      });
    }
  }
};
</script>

<style scoped>
.el-container {
  height: 100%;
  width: 100%;
}
.wrap {
  height: 100%;
  width: 100%;
}
</style>